package com.link.base.base.customerpricehistory.controller;

import com.link.base.base.customerpricehistory.model.CustomerPriceHistory;
import com.link.base.base.customerpricehistory.service.CustomerPriceHistoryService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.query.QueryParams;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 客户价格履历表
 *
 * @author 刘守龙
 * @date 2024-03-31 12:09:39
 */
@Controller
@RequestMapping("/link/customerPriceHistory")
public class CustomerPriceHistoryController extends BasicController<CustomerPriceHistory> {

    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private CustomerPriceHistoryService customerPriceHistoryService;

    @Override
    public BasicService<CustomerPriceHistory> getBasicService() throws Exception {
        return customerPriceHistoryService;
    }

    @RequestMapping({"/addExcelData"})
    @ResponseBody
    public Map<String, Object> addExcelData(@JsonParam CustomerPriceHistory entity,
                                            QueryParams qps,
                                            HttpSession session,
                                            HttpServletRequest request,
                                            HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            if (null == entity.getAttachmentId()) {
                throw new Exception("上传文件数据丢失!");
            }
            customerPriceHistoryService.insertExcelData(entity.getAttachmentId());
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

}
